package com.rk.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rk.common.result.Result;
import com.rk.hosp.model.user.UserInfo;
import com.rk.hosp.vo.user.UserInfoQueryVo;
import com.rk.user.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author :Rk.
 * @date : 2022/11/27
 */

@Api(tags = "用户管理")
@RestController
@RequestMapping("/admin/user")
public class UserController {


    @Autowired
    private UserInfoService userInfoservice;


    //用户列表（条件查询带分页）
    @ApiOperation("查询用户列表")
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> pageParam = new Page<>(page,limit);
        IPage<UserInfo> pageModel =
                userInfoservice.selectPage(pageParam,userInfoQueryVo);
        return Result.ok(pageModel);
    }



    @ApiOperation("用户锁定")
    @GetMapping("/lock/{userId}/{status}")
    public Result lockUser(@PathVariable Long userId, @PathVariable Integer status) {

        userInfoservice.lockUser(userId,status);

        return Result.ok();
    }

    @ApiOperation("用户详情")
    @GetMapping("/show/{userId}")
    public Result showUser(@PathVariable Long userId) {
        Map<String, Object> map = userInfoservice.showUser(userId);
        return Result.ok(map);
    }

    @ApiOperation("用户认证审批")
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId,
                           @PathVariable Integer authStatus) {
        userInfoservice.approval(userId,authStatus);
        return Result.ok();
    }
}
